package com.zggk.lzz.roadt;

import com.alibaba.fastjson.JSON;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.mvp.BasePresenterImpl;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class RoadTPresenter extends BasePresenterImpl<RoadTContract.View> implements RoadTContract.Presenter{
    @Override
    public void getXZData() {
        OkGo.<String>post(Urls.JAVASERVER6 + "rural/routeDistribution/getJXMileageStatisticsNewNcgl")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token", ""))
                .params("selectType", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (mView == null)
                            return;
                        List<RoadKJBean> roadKJBeans = JSON.parseArray(response.body(), RoadKJBean.class);
                        List<XzBean> xzBeanList = new ArrayList<>();
                        for (int i = 0; i < 5; i++) {
                            XzBean xzBean = new XzBean();
                            if (i==0){//合计
                                xzBean.setRoad_length(roadKJBeans.get(0).getRoadLength());
                                xzBean.setRoad_type("Z");
                            }else if (i==1){//县道
                                xzBean.setRoad_length(roadKJBeans.get(0).getFirstHighway());
                                xzBean.setRoad_type("X");
                            }else if (i==2){//乡道
                                xzBean.setRoad_length(roadKJBeans.get(0).getSecondHighway());
                                xzBean.setRoad_type("XD");
                            }else if (i==3){//村道
                                xzBean.setRoad_length(roadKJBeans.get(0).getThreeHighway());
                                xzBean.setRoad_type("C");
                            }else if (i==4){//专道
                                xzBean.setRoad_length(roadKJBeans.get(0).getFourHighway());
                                xzBean.setRoad_type("ZD");
                            }
                            xzBeanList.add(xzBean);
                        }
                        mView.getXZDatas(xzBeanList);
                    }
                });
    }
    @Override
    public void getJSData() {
        OkGo.<String>post(Urls.JAVASERVER6 + "rural/routeDistribution/getJXMileageStatisticsNew")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token", ""))
                .params("selectType", "0")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (mView == null)
                            return;
                        List<RoadKJBean> roadKJBeans = JSON.parseArray(response.body(), RoadKJBean.class);
                        List<XzBean> xzBeanList = new ArrayList<>();
                        for (int i = 0; i < 6; i++) {
                            XzBean xzBean = new XzBean();
                            if (i==0){//合计
                                xzBean.setRoad_length(roadKJBeans.get(0).getRoadLength());
                                xzBean.setRoad_type("HJ");
                            }else if (i==1){//一级公路
                                xzBean.setRoad_length(roadKJBeans.get(0).getFirstHighway());
                                xzBean.setRoad_type("YJ");
                            }else if (i==2){//二级公路
                                xzBean.setRoad_length(roadKJBeans.get(0).getSecondHighway());
                                xzBean.setRoad_type("EJ");
                            }else if (i==3){//三级公路
                                xzBean.setRoad_length(roadKJBeans.get(0).getThreeHighway());
                                xzBean.setRoad_type("SJ");
                            }else if (i==4){//四级公路
                                xzBean.setRoad_length(roadKJBeans.get(0).getFourHighway());
                                xzBean.setRoad_type("SIJ");
                            }else if (i==5){//等外公路
                                xzBean.setRoad_length(roadKJBeans.get(0).getOvergaugeHighway());
                                xzBean.setRoad_type("DW");
                            }
                            xzBeanList.add(xzBean);
                        }
                        mView.getJSDatas(xzBeanList);
                    }
                });
    }
    @Override
    public void getLXData() {
        OkGo.<String>post(Urls.JAVASERVER6 + "rural/routeDistribution/getJXMileageStatisticsNew")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token", ""))
                .params("selectType", "2")
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (mView == null)
                            return;
                        List<RoadKJBean> roadKJBeans = JSON.parseArray(response.body(), RoadKJBean.class);
                        List<XzBean> xzBeanList = new ArrayList<>();
                        for (int i = 0; i < 4; i++) {
                            XzBean xzBean = new XzBean();
                            if (i==0){//合计
                                xzBean.setRoad_length(roadKJBeans.get(0).getRoadLength());
                                xzBean.setRoad_type("HJ");
                            }else if (i==1){//沥青
                                xzBean.setRoad_length(roadKJBeans.get(0).getAsphaltRoad());
                                xzBean.setRoad_type("LQ");
                            }else if (i==2){//水泥
                                xzBean.setRoad_length(roadKJBeans.get(0).getCementRoad());
                                xzBean.setRoad_type("SN");
                            }else if (i==3){//砂石
                                xzBean.setRoad_length(roadKJBeans.get(0).getSimpleRoad());
                                xzBean.setRoad_type("SS");
                            }
                            xzBeanList.add(xzBean);
                        }
                        mView.getLXDatas(xzBeanList);
                    }
                });
    }
}
